package com.apobates.jforum2.troll.nest.controller;

import com.apobates.jforum2.troll.forum.stub.vo.BoardGroupCollectVo;
import com.apobates.jforum2.troll.forum.stub.vo.BoardGroupVo;
import com.apobates.jforum2.troll.nest.service.BoardGroupClient;
import java.util.List;
import java.util.Optional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * 版块组(卷)服务API控制器
 * @author xiaofanku
 * @since 20210413
 */
@RestController
@RequestMapping("/api/boardgroup")
public class BoardGroupClientController {
    @Autowired
    private BoardGroupClient boardGroupClient;
    
    //1:指定的版块组
    @GetMapping("/{id}")
    public BoardGroupVo get(@PathVariable("id")int boardGroupId){
        ResponseEntity<BoardGroupVo> rs = boardGroupClient.get(boardGroupId);
        return Optional.ofNullable(rs.getBody()).orElse(new BoardGroupVo());
    }
    
    //2:指定版块组的图标
    @GetMapping("/{volume}/ico/{scale}")
    public String getIco(@PathVariable("volume")int boardGroupId, @PathVariable("scale")String scale){
        ResponseEntity<String> rs = boardGroupClient.getIco(boardGroupId, scale);
        return Optional.ofNullable(rs.getBody()).orElse("/ico/default_icon.png");
    }
    
    //3:所有的版块组
    @GetMapping("/all")
    public List<BoardGroupVo> getAllUsed(){
        return boardGroupClient.getAllUsed();
    }
    
    //4:所有的版块组,级联加载版块组下的版块
    @GetMapping("/all/cascade/{defed}")
    public List<BoardGroupCollectVo> getAllCascadeUsedBoard(@PathVariable("defed")int containsDefault){
        return boardGroupClient.getAllCascadeUsedBoard(containsDefault);
    }
    
    //5:指定的版块组,级联加载版块组下的版块
    @GetMapping("/{volume}/cascade")
    public BoardGroupCollectVo getCascadeUsedBoard(@PathVariable("volume")int boardGroupId){
        ResponseEntity<BoardGroupCollectVo> rs = boardGroupClient.getCascadeUsedBoard(boardGroupId);
        return Optional.ofNullable(rs.getBody()).orElse(new BoardGroupCollectVo());
    }
}